// pages/case/case.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		casesList2: [],

		start: 0,
		page: 1,
		size: 6,
		isEnd: false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		this.getData(this.data.casesList2, this.data.start);
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		//获取更多
		this.data.start = this.data.page * this.data.size;
		this.getData(this.data.casesList2, this.data.start);

		this.data.page += 1;

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	},
	//
	getData: function(lastData, start) {
		var that = this;
		var url_ = getApp().globalData.url_;
		if (this.data.isEnd) {
			return
		}
		// 首页  获取banner
		wx.request({
			url: url_ + '/api/excellent_cases/all?start=' + start + '&count=' + that.data.size,
			method: "GET",
			dataType: "json",
			success: function(res) {
				// console.log(res.data.data)
				var currentData = res.data.data

				for (let j = 0; j < currentData.length; j++) {
					var img = url_ + currentData[j].image;
					currentData[j].image = img;
				}
				var lastData_ = lastData;
				lastData_.push(...currentData)
				that.setData({
					casesList2: lastData_,
				})
				// console.log(currentData.length)
				if (currentData.length < that.data.size || !currentData) {
					that.setData({
						isEnd: true
					})
				}
			},
			fail: function(e) {
				console.log("请求失败");
			},
		})
	},
	//跳转
	caseGoDetail2: function(e) {
		// console.log(e.currentTarget.dataset.id)
		wx.navigateTo({
			url: "../case/caseDetails?id=" + e.currentTarget.dataset.id
		})
	}
})
